package com.joshua.viewtest.demo.TopToolBarTest;

import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.joshua.viewtest.R;

import butterknife.BindView;
import butterknife.ButterKnife;

public class TopToolBarAty extends AppCompatActivity {
    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.drawer_layout)
    DrawerLayout mDrawerLayout;

    private ActionBarDrawerToggle mToggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_top_tool_bar_aty);
        ButterKnife.bind(this);

        mToolbar.setTitle("Title");
        mToolbar.setSubtitle("SubTitle");
        setSupportActionBar(mToolbar);

        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        mToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string
                .drawer_open, R.string.drawer_close);
        mToggle.syncState();
        mDrawerLayout.addDrawerListener(mToggle);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.toolbar_test_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_search:
                Toast.makeText(TopToolBarAty.this, "Search", Toast.LENGTH_SHORT)
                        .show();
                break;
            case R.id.action_share:
                Toast.makeText(TopToolBarAty.this, "Share", Toast.LENGTH_SHORT)
                        .show();
                break;
            case R.id.action_setting:
                Toast.makeText(TopToolBarAty.this, "Setting", Toast.LENGTH_SHORT)
                        .show();
                break;
        }
        return true;
    }
}
